﻿@model NCP.Recruiting.WebApp.Models.CompanyFormModel
@{
    ViewBag.Title = "Edit";
}
@if (false)
{ 
    <script src="../../Scripts/jquery-1.7.1-vsdoc.js" type="text/javascript"></script>
}
@Html.Partial("_CreateOrUpdate", Model)
<div id="publishBtns">
    <div class="publishBtns_contents">
        <p>@Html.ActionLink("取消", "Index", "Home")
            <input value="保存" class="btnbluecss" type="submit" name="SaveInfo" id="SaveInfo" /></p>
    </div>
</div>
<script type="text/javascript">

    $(document).ready(function () {
        $("#EstablishedOn").datepicker({ dateFormat: 'yy/mm/dd',
            showButtonPanel: true,
            showOn: 'button',
            buttonImage: "/Content/images/calendar.gif",
            buttonImageOnly: true
        });


        //tab菜单切换事件
        $('.tabMenus ul li').click(function () {
            $('.tabMenus ul li.tab_cur').removeClass('tab_cur');
            $(this).addClass('tab_cur');
            var Index = $(this).index();
            $('.tab01').eq(Index).show().siblings().hide();
        });

        //省市选择
        $("#Province").change(function () {
            $("#City").get(0).options.length = 0; //清空
            $("<option value=''>请选择</option>").appendTo($("#City"));
            $.getJSON("/Company/GetCities/" + $(this).val(), null, function (data) {
                $.each(data, function (i, item) {
                    $("<option></option>").val(item["Value"]).text(item["Name"]).appendTo($("#City"));
                });
            });
        });

        //公司信息提交事件--start

        var saveinfooptions = {
            beforeSubmit: validate,
            success: showResponse
        }

        $('#SaveInfo').click(function () {

            $('#SaveEdit').submit();

        });

        $('#SaveEdit').submit(function () {

            $(this).ajaxSubmit(saveinfooptions);

            return false;

        });

        //设置Logo图片选择路径
        $("#logofile").change(function () {

            $("#logosource").val($(this).val());

        });
        //公司信息提交事件--end

        //照片墙上传图片提交事件--start
        var savefileoptions = {
            success: showfileResponse
        }

        $('#SaveImage').submit(function () {

            $(this).ajaxSubmit(savefileoptions);

            return false;

        });

        //照片墙上传图片提交事件--end


        //设置照片墙图片选择路径
        $("#filewall").change(function () {

            $("#filewallurl").val($(this).val());

        });


        //上传照片墙图片
        $("#FileWallUpload").click(function () {

            //$(".Photo_wall > ul").append("<li><img src='/Company/GetImage?fileid=7c3f70bf-5223-c1a3-6d45-08d0febe84eb' width='200' height='120'/></li>");

            //判断是否有选择上传文件  
            var imgPath = $("#filewall").val();
            if (imgPath == "") {
                alert("请选择上传图片！");
                return false;
            }
            //判断上传文件的后缀名  
            var strExtension = imgPath.substr(imgPath.lastIndexOf('.') + 1);
            if (strExtension != 'jpg' && strExtension != 'gif'
            && strExtension != 'png' && strExtension != 'bmp') {
                alert("请选择图片文件");
                return false;
            }

        });

        //照片墙删除操作
        $('.Photo_wall ul li a').click(function () {

            $.ajax({
                type: 'POST',
                url: "/Company/DeleteImg?id=" + $(this).parent().parent().attr("id"),
                success: success,
                dataType: "json"
            });
            return false;

        });

    });

    function success(data) {

        $('.Photo_wall ul li:[id=' + data + ']').remove();

    }

    $('#deletelogo').click(function () {

        $.ajax({
            type: 'POST',
            url: "/Company/DeleteLogo",
            success: successlogo,
            dataType: "json"
        });
        return false;

    });

    function successlogo(data) {

        $('#ComapnyLogo').attr("src","");

    }

    function showResponse(responseText, statusText) {

        if (responseText == "SaveInfo") {

            
            alert("保存成功");
        }
        else {
            $("#ComapnyLogo").attr("src", "/Company/GetLogoImage?t=" + Math.random());
            $("#logosource").val("");
            $("#logofile").val("");
            alert("Logo上传成功");
        }
    }

    function showfileResponse(responseText, statusText) {

        //alert(responseText);
        $(".Photo_wall > ul").html("");
        $.each(responseText, function (i) {
            var id = responseText[i].Id;
            var title = responseText[i].Title;
            var html = "<li><a href='#'><img src='/Company/GetImage?fileid=" + id + "' width='200' height='120'/></a><p><span>" + title + "</span> <a href='#'>删除</a><div class='cr'></div></p></li>";
            //alert($(".Photo_wall > ul").html())

            $(".Photo_wall > ul").append(html);
            $("#filewall").val("");
            $("#filewallurl").val("");
        });  

        //$("#Photo_wall ul").append("<img src="+"/Company/GetImage?fileid="+name+" width='200' height='120'/>");
        //alert(responseText);
    }

    function validate(formData, jqForm, options) {

        var usernameValue = $('input[id=BusinessLicense]').fieldValue();

        // usernameValue and passwordValue are arrays but we can do simple 
        // "not" tests to see if the arrays are empty 
        if (!usernameValue[0]) {
            return false;
        }
    }
</script>
